<template>
  <div class="pd-20">
    <el-input v-model="doctorName"
              clearable
              class="w-200"
              placeholder="请输入病种名称"
              @clear="handleQuery"></el-input>
    <el-button type="primary"
               @click="handleQuery">查 询</el-button>
    <el-button type="primary"
               @click="handleOption('add', null)">新 增</el-button>
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:option="{row}">
        <el-button type="danger"
                   @click="handleOption('del', row)">删 除</el-button>
      </template>
    </element-table>
    <featured-dialog :dataObj="dataObj"
                     v-if="dialogVisible"
                     :visible.sync="dialogVisible"></featured-dialog>
  </div>
</template>
<script>
  import ElementTable from '@/base/ElementTable'
  import featuredDialog from './featuredDialog'
  export default {
    name: 'diseaseList', // 精选医生
    data () {
      return {
        loading: false,
        dialogVisible: false,
        doctorName: '',
        tableData: [],
        columns: [
          {
            label: '医生姓名',
            prop: 'doctorName'
          }, {
            label: '职称',
            prop: 'doctorTitleName'
          }, {
            label: '科室',
            prop: 'departmentName'
          }, {
            label: '所属医院',
            prop: 'doctorTitleName'
          }, {
            label: '覆盖省份',
            prop: 'provinceName'
          }, {
            label: '操作',
            prop: 'option',
            align: 'center',
            isSlot: true,
            width: 150
          }
        ],
        pageTotal: 0,
        pageIndex: 1,
        pageSize: 20,
        dataObj: {}
      }
    },
    methods: {
      handleQuery() {
        this.pageIndex=1
        this.getList()
      },
      async getList () {
        this.loading = true;
        const { data: res } = await this.post(this.api.doctorManager.getWellChosenDoctor, {
          doctorName: this.doctorName,
          pageIndex: this.pageIndex - 1,
          pageSize: this.pageSize,
        });
        if (res.code === '200') {
          this.loading = false;
          this.tableData = res.object;
          this.pageTotal = res.totalNum;
        }
      },
      // 分页
      handleChangePage (page) {
        this.pageIndex = page;
        this.getList();
      },
      async handleOption (op, row) {
        switch (op) {
          case 'add':
            this.dataObj = null;
            this.dialogVisible = true;
            break;
          case 'del':
            this.$confirm('确认删除？')
              .then(async _ => {
                const { data: res } = await this.post(this.api.doctorManager.delWellChosenDoctor, { id: row.id })
                if (res.code === '200') {
                  this.$message.success('删除成功!');
                  this.getList();
                }
              })
              .catch(_ => { });
            break;
        }
      }
    },
    created () {
      this.getList();
    },
    components: {
      'element-table': ElementTable,
      'featured-dialog': featuredDialog
    }
  }
</script>
<style scoped lang="scss">
</style>
